<%--***************************************
*
*银联
* 
***************************************--%>
<%@ page import="
	java.util.*,
	java.math.*,
	chinapay.*,
	com.probiz.estore.Constants,
	com.probiz.estore.order.model.OnlinePaymentResponse,
	com.probiz.estore.common.model.system.PaymentGateway,
	com.probiz.estore.system.service.PaymentGatewayManager,
	com.probiz.estore.common.service.OrderService,
	org.springframework.web.context.support.WebApplicationContextUtils,
	org.springframework.web.context.WebApplicationContext"
	pageEncoding="UTF-8"%>
 
 <%
	WebApplicationContext webAppContext = WebApplicationContextUtils.getWebApplicationContext(pageContext.getServletContext());
	PaymentGatewayManager paymentGatewayManager = (PaymentGatewayManager) webAppContext.getBean("paymentGatewayManager");
	PaymentGateway paymentGateway = paymentGatewayManager.getByPaymentGatewayCode("chinaPay");
	HashMap paramMap=paymentGateway.getConfigData();
	//检查该数据是否为支付网关的通知数据。
	String merId = paramMap.get("merId").toString();
	String pgPubk = paramMap.get("pgPubk").toString();
	String orderId = request.getParameter("orderno");
	String orderNo = request.getParameter("Priv1");
	String amountStr = request.getParameter("amount");
	String transdate = request.getParameter("transdate");
	String transtype = request.getParameter("transtype");
	String currencycode=request.getParameter("currencycode");
	String checkvalue = request.getParameter("checkvalue");
	String status = request.getParameter("status");
	
	PrivateKey key = new PrivateKey();
	SecureLink t;
	boolean flag = false;
	//status 表示交易转态，只有"1001"的时候才为交易成功
	if("1001".equals(status)){
		try{
			boolean buildKeyFlag = false;
			//999999999999999是银行商户,固定的;
			buildKeyFlag = key.buildKey("999999999999999", 0, pgPubk);
			t = new SecureLink(key);
			flag = t.verifyTransResponse(merId, orderId, amountStr, currencycode, transdate, transtype,status, checkvalue);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	BigDecimal amount = new BigDecimal(Long.parseLong(amountStr,10)+"").divide(new BigDecimal(100)).setScale(2, RoundingMode.UP);
	
	OnlinePaymentResponse onlinePaymentResponse = new OnlinePaymentResponse();
	onlinePaymentResponse.setFlowNo(orderNo);   //必填. 如果支付网关没有流水号，则使用原始的orderNo，即未decode前的
	onlinePaymentResponse.setOrderNo(orderNo);  //必填
	onlinePaymentResponse.setFlag(flag?Constants.PAYMENT_HISTORY_FLAG_SUCCESS:Constants.PAYMENT_HISTORY_FLAG_FAILURE);    //必填
	onlinePaymentResponse.setAmount(amount);  //必填
	onlinePaymentResponse.setPaymentGateway(paymentGateway);  //必填
	OrderService orderService = (OrderService) webAppContext.getBean("orderService");
	request.setAttribute("onlinePaymentResponse",onlinePaymentResponse);
	orderService.doHandleOnlinePaymentResponse(onlinePaymentResponse,request);
 %>
 
 <%@include file="./include/finishPayResult.jspf"%>